'''
    @Author:webrainer
    @Date:today
    @Version:
    @Since:python3.11
    @See:
    @Description:  模块，实现了   基本功能
    @Functions:
'''
# -*- coding: UTF-8 -*-
import requests
import time

#五个指数为上证指数，深圳成指，沪深500，北证50，创业板指
def get_index():
    # 爬虫阶段
    url = 'https://hq.sinajs.cn/rn=1686104852928&list=s_sh000001,s_sz399001,s_sh000300,s_bj899050,s_sz399006'
    headers = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36 Edg/114.0.1823.37',
        'Referer': 'https://finance.sina.com.cn/',
    }
    res = requests.get(url, headers=headers)
    res_text = res.text
    res_text = res_text.split(';')[:-1]
    shangzheng = res_text[0]
    shenzheng = res_text[1]
    hs300 = res_text[2]
    bz50 = res_text[3]
    chuangye = res_text[4]
    for i in range(0, len(shangzheng)):
        if shangzheng[i] == '上':
            shangzheng = shangzheng[i:].split(',')
            break
    for i in range(0, len(shenzheng)):
        if shenzheng[i] == '深':
            shenzheng = shenzheng[i:].split(',')
            break
    for i in range(0, len(hs300)):
        if hs300[i] == '沪':
            hs300 = hs300[i:].split(',')
            break
    for i in range(0, len(bz50)):
        if bz50[i] == '北':
            bz50 = bz50[i:].split(',')
            break
    for i in range(0, len(chuangye)):
        if chuangye[i] == '创':
            chuangye = chuangye[i:].split(',')
            break
    return (shangzheng, shenzheng, hs300, bz50, chuangye)

if __name__=="__main__":
    print(get_index())